<?php
$this->breadcrumbs = array(
    'MLM System',
    'Members' => array('list'),
    'Testimony List',
);

$this->menu = array();

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('sys-member-testimony-grid', {
            data: $(this).serialize()
	});
	return false;
});
");
?>
<?php if (Yii::app()->user->hasFlash('success')): ?>
    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/success.png">
        <?php echo Yii::app()->user->getFlash('success'); ?>
    </div>
<?php endif; ?>
<?php if (Yii::app()->user->hasFlash('error')): ?>
    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/alert_2.png">
        <?php echo Yii::app()->user->getFlash('error'); ?>
    </div>
<?php endif; ?>
<?php
echo CHtml::form(Yii::app()->baseUrl . "/admin/system/testimony/publish", 'post');
?>
<div class="flat_area grid_16">
    <h2>List of Testimony</h2>
    <?php if($this->action_publish == 1) : ?>
    <button class="button_colour round_all" name="publish"><img height="24" width="24" alt="Bended Arrow Right" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/white/bended_arrow_right.png"><span>Publish</span></button>
    <button class="button_colour round_all" name="unpublish"><img height="24" width="24" alt="Bended Arrow Right" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/white/bended_arrow_right.png"><span>Unpublish</span></button>
    <?php endif; ?>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'sys-member-testimony-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        array('header' => '#',
            'type' => 'raw',
            'value' => 'CHtml::checkBox("item[]", false, array("value" => $data->member_testimony_id));',
            'htmlOptions' => array('style' => 'text-align:center;')),
        array(
            'header' => 'No.',
            'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)."."',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'header' => 'Member ID',
            'value' => '$data->network_mid',
        ),
        array(
            'header' => 'Member Name',
            'value' => 'function_lib::get_member_name($data->member_testimony_network_id)',
        ),
        array(
            'header' => 'Testimony',
            'type' => 'raw',
            'value' => 'nl2br($data->member_testimony_content)',
        ),
        array(
            'header' => 'Post Date',
            'value' => '$data->member_testimony_input_datetime',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'name' => 'member_testimony_is_approve',
            'type' => 'image',
            'value' => '($data->member_testimony_is_approve == 1 ? Yii::app()->request->baseUrl . "/images/icon/b_ok.png" : Yii::app()->request->baseUrl . "/images/icon/b_notok.png")',
            'filter' => CHtml::activeDropDownList($model, 'member_testimony_is_approve', array('' => '', '1' => 'Published', '0' => 'Unpublished')),
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
    ),
    'selectableRows' => 1,
    'selectionChanged' => 'userClicks',
    'pager' => array(
        'cssFile' => Yii::app()->params['backendUrl'] . '/css/style-pager.css',
        'header' => '',
        'firstPageLabel' => 'First',
        'prevPageLabel' => 'Previous',
        'nextPageLabel' => 'Next',
        'lastPageLabel' => 'Last',
    ),
    'cssFile' => Yii::app()->params['backendUrl'] . '/css/style-gridview.css',
    'loadingCssClass' => '',
));
echo CHtml::endForm();
?>
<script>
    var id = 0;
    function userClicks(target_id) {
        id = $.fn.yiiGridView.getSelection(target_id);
    }
</script>